<template>
    <div>
      <table class="table table-bordered">
        <tbody>
            <tr>
                <td>项目名称</td>
                <td><input type="text" v-model="data.kname"></td>
            </tr>
              <tr>
                <td>项目编号</td>
                <td><input type="text" v-model="data.bian" disabled></td>
            </tr>
              <tr>
                <td>佣金</td>
                <td><input type="text" v-model="data.price"></td>
            </tr>
              <tr>
                <td>服务人数</td>
                <td><input type="text" v-model="data.num"></td>
            </tr>
            <tr>
                <td>服务时长</td>
                <td><input type="text" v-model="data.shi"></td>
            </tr>
              <tr>
                <td>项目说明</td>
                <td><textarea v-model="data.shuo"></textarea></td>
            </tr>
              <tr>
                <td>状态</td>
                <td><input type="radio" :value="1" v-model="data.flag">启用
                <input type="radio" :value="0" v-model="data.flag">禁用</td>
            </tr>
       
              <tr>
                <td></td>
                <td><input type="button" value="新增" @click="add()"></td>
            </tr>
        </tbody>
      </table>
    </div>
</template>

<script setup lang="ts">
import moment from 'moment';
import axios from 'axios';
import { onMounted, ref} from 'vue'
import {useRoute,useRouter} from 'vue-router'
import router from '@/router';

let data:any = ref({
"kname": "",
  "bian": moment().format("YYYYMMDD") + Math.random().toString().substring(2,5),
  "price": '',
  "num": '',
  "shi": '',
  "shuo": "",
  "flag": 1,
})
const add=()=>{
    if(data.value.kname=="")
    {
        alert("项目名称不能为空")
        return;
    }
    if(data.value.price=="")
    {
        alert("佣金不能为空")
        return;
    }
    if(data.value.num=="")
    {
        alert("服务人数不能为空")
        return;
    }
    if(data.value.num*0!=0)
    {
        alert("服务人数只能为整数")
        return;
    }
     if(data.value.shi=="")
    {
        alert("服务时长不能为空")
        return;
    } 
      if(data.value.shi*0!=0)
    {
        alert("服务时长只能为整数")
        return;
    }
    axios({
        url:"https://localhost:7265/api/Kang/Add",
        method:'post',
        data:data.value
    })
    .then(res=>{
        if(res.data>0)
        {
            alert('新增成功')
            router.push("/demo4")
        }
        else
        {
            alert("新增失败")
            return
        }
    })
}
</script>

<style scoped>

</style>